<template>
  <div>
    <p class="pinformation" style="margin-top: 7px">搜索条件</p>
    <el-form label-width="100px" :model="queryParams" ref="queryRef">
      <el-row>
        <el-col :span="4">
          <el-form-item label="原报告编号：" prop="reportCode">
            <el-input
              v-model="queryParams.reportCode"
              clearable
              maxlength="100"
              @keyup.enter="handeleQuery"
              placeholder="请输入原报告编号"
            ></el-input>
          </el-form-item>
        </el-col>
        <el-col :span="4">
          <el-form-item label="原报告名称：" prop="a">
            <el-input
              v-model="queryParams.a"
              clearable
              maxlength="100"
              @keyup.enter="handeleQuery"
              placeholder="请输入原报告名称"
            ></el-input>
          </el-form-item>
        </el-col>
        <el-col :span="4">
          <el-form-item label="委托单位：" prop="wtCustomName">
            <el-input
              v-model="queryParams.wtCustomName"
              clearable
              maxlength="100"
              @keyup.enter="handeleQuery"
              placeholder="请输入委托单位"
            ></el-input>
          </el-form-item>
        </el-col>
        <el-col :span="4">
          <el-form-item label="受检单位：" prop="sjCustomName">
            <el-input
              v-model="queryParams.sjCustomName"
              clearable
              maxlength="100"
              @keyup.enter="handeleQuery"
              placeholder="请输入受检单位"
            ></el-input>
          </el-form-item>
        </el-col>
        <el-col :span="4">
          <el-form-item label="报告类型：" prop="b">
            <el-input
              v-model="queryParams.b"
              clearable
              maxlength="100"
              @keyup.enter="handeleQuery"
              placeholder="请输入报告类型"
            ></el-input>
          </el-form-item>
        </el-col>
      </el-row>
      <el-row>
        <el-col :span="4">
          <el-form-item label="编制人：" prop="projectCode">
            <el-input
              v-model="queryParams.projectCode"
              clearable
              maxlength="100"
              @keyup.enter="handeleQuery"
              placeholder="请输入编制人"
            ></el-input>
          </el-form-item>
        </el-col>
        <el-col :span="4">
          <!-- planDate -->
          <el-form-item label="变更申请时间：">
            <el-date-picker
              v-model="dateRange"
              value-format="YYYY-MM-DD"
              type="daterange"
              :clearable="false"
              :editable="false"
              range-separator="-"
              start-placeholder="开始日期"
              end-placeholder="结束日期"
            ></el-date-picker>
          </el-form-item>
        </el-col>
        <el-col :span="4">
          <el-form-item label="当前状态：" prop="status">
            <el-input
              v-model="queryParams.status"
              clearable
              maxlength="100"
              @keyup.enter="handeleQuery"
              placeholder="请输入当前状态"
            ></el-input>
          </el-form-item>
        </el-col>
        <el-col :span="4">
          <el-form-item label="合同编号：" prop="contractCode">
            <el-input
              v-model="queryParams.contractCode"
              clearable
              maxlength="100"
              @keyup.enter="handeleQuery"
              placeholder="请输入合同编号"
            ></el-input>
          </el-form-item>
        </el-col>
        <el-col :span="4">
          <el-row justify="end">
            <el-button type="success" @click="handeleQuery">搜索</el-button>
            <el-button class="business resetBtn" @click="resetQuery"
              >重置</el-button
            >
          </el-row>
        </el-col>
      </el-row>
    </el-form>
    <el-row>
      <p class="pinformation">
        报告变更申请列表
      </p>
      <p class="totalStyle">共 {{ total }} 条数据</p>
    </el-row>
    <el-table ref="mainTableRef" :data="projectList" v-loading="loading">
      <el-table-column prop="reportCode" label="原报告编号" align="center" />
      <el-table-column prop="projectName" label="原报告名称" align="center" />
      <el-table-column prop="wtCustomName" label="委托单位" align="center" />
      <el-table-column prop="" label="报告类型" align="center" />
      <el-table-column prop="updateTime" label="编制时间" align="center" />
      <el-table-column prop="" label="编制人" align="center" />
      <el-table-column prop="" label="变更申请人" align="center" />
      <el-table-column prop="updateTime" label="变更申请时间" align="center" />
      <el-table-column prop label="操作" align="center">
        <template #default="scope">
          <el-button
            link
            type="success"
            v-if="props.archiveStatus == 1"
            @click="handleDistri(scope.row)"
            >编辑</el-button
          >
          <el-button
            link
            type="success"
            v-if="props.archiveStatus == 1"
            @click="handleDistri(scope.row)"
            >删除</el-button
          >
        </template>
      </el-table-column>
    </el-table>
    <pagination
      v-show="total > 0"
      :total="total"
      v-model:page="queryParams.pageNum"
      v-model:limit="queryParams.pageSize"
      @pagination="handeleQuery"
    />
  </div>
</template>

<script setup>
import { getArchiveList } from "@/api/projectArchive/index";
import { getTemplateList } from "@/api/report/reportProject";

const { proxy } = getCurrentInstance();
const { sys_degree } = proxy.useDict("sys_degree");
const router = useRouter();
const projectList = ref([]);
const total = ref(0);
const dateRange = ref([]);
const loading = ref(false)
const data = reactive({
  form: {},
  queryParams: {
    pageNum: 1,
    pageSize: 10,
    degree: -1,
  },
});
const { queryParams, form } = toRefs(data);
const props = defineProps({
  archiveStatus: {
    type: Number, //参数类型
  },
});
const emits = defineEmits(["archiveFileId"]);

function handeleQuery() {
  queryParams.value.archiveStatus = props.archiveStatus;
  loading.value = true
  getArchiveList(proxy.addDateRange(queryParams.value, dateRange.value)).then(
    (res) => {
      loading.value = false
      projectList.value = res.rows;
      total.value = res.total;
    }
  );
}

function handleDistri(row) {
  emits("archiveFileId", row.archiveFileId);
}

function resetQuery() {
  proxy.resetForm("queryRef");
  dateRange.value = [];
  handeleQuery();
}

defineExpose({
  getTableHeight,
});

watch(
  () => total.value,
  () => {
    if (total.value) {
      heightParams.value = [{ tableName: "main", bottomHeight: 73 }];
    } else {
      heightParams.value = [{ tableName: "main", bottomHeight: 22 }];
    }
    getTableHeight();
  }
);

const heightParams = ref([{ tableName: "main", bottomHeight: 22 }]);
function getTableHeight() {
  proxy.adaptiveHeight(proxy, heightParams.value);
}
onMounted(() => {
  nextTick(() => {
    getTableHeight();
    window.addEventListener("resize", getTableHeight);
  });
});
onUpdated(() => {
  nextTick(function () {
    getTableHeight();
  });
});
onBeforeUnmount(() => {
  window.removeEventListener("resize", getTableHeight);
});
handeleQuery();

const templateList = ref([]);
getTemplateList().then((res) => {
  templateList.value = res.data;
});
</script>

<style></style>
